<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>乐淘 - 后台管理系统</title>
    <!--bootstrap 的样式-->
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
    <!--  小图标 -->
    <link rel="stylesheet" href="assets/font-awesome/css/font-awesome.css">
    <!-- 这个文件是页面的样式. -->
    <link rel="stylesheet" href="less/index.css">
</head>
<body>
<!-- 登录 -->
<div class="login">
    <div class="login-wrap">
        <div class="avatar">
            <img src="images/monkey.png" class="img-circle" alt="">
        </div>
        <form action="" class="col-md-offset-1 col-md-10">
            <div class="input-group input-group-lg">
                    <span class="input-group-addon">
                        <i class="fa fa-user"></i>
                    </span>
                <input type="text" class="form-control" id="username" placeholder="用户名">
            </div>
            <div class="input-group input-group-lg">
                    <span class="input-group-addon">
                        <i class="fa fa-key"></i>
                    </span>
                <input type="password" class="form-control" id="password" placeholder="密码">
            </div>
            <button type="button" class="btn btn-lg btn-primary btn-block">登 录</button>
        </form>
    </div>
</div>
<!--jQuery-->
<script src="assets/jquery/jquery.min.js"></script>
<!--bootstrap 的核心文件.-->
<script src="assets/bootstrap/js/bootstrap.min.js"></script>

<script>
    $(function () {

        function login() {

            var username = $("#username").val();
            var password = $("#password").val();

            if (!username) {
                alert("请输入正确的用户名");
                return;
            }
            if (!password) {
                alert("请输入正确的密码");
                return;
            }

            $.ajax({
                url: "/employee/employeeLogin",
                dataType: "json",
                type: "POST",
                data: {
                    username: username,
                    password: password
                },
                success: function (data) {
                    console.log(data);
                    if (data.success) {
                        //跳转到首页
                        window.location.href = "index.html";
                    } else {

                        alert(data.message);

                    }
                }
            })


        }

        /*给登录按钮添加点击事件，点击登录，处理逻辑*/
        $(".btn-lg").on("click", function () {
            login();
        });

        //我还需要做一个快捷点登录.

        $(document).keyup(function (event) {
            //判断event 的值keyCode 的值，
            //如果这个keyCode 的值等于13 ，说明用户按的是enter 键
            if (event.keyCode == 13) {
                login();
            }
        })

    })


</script>

</body>
</html>